﻿using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using SmartCity.ProcessEngine.Api.Write.Application.Command.Form;
using SmartCity.ProcessEngine.Api.Write.Application.Command.FormCategory;
using SmartCity.ProcessEngine.Api.Write.Application.Command.FormDetail;
using SmartCity.ProcessEngine.ErrorCode;

namespace SmartCity.ProcessEngine.Api.Write.Controllers
{
   /// <summary>
   /// 流程引擎控制器
   /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class ProcessEngineController : ControllerBase
    {
        private readonly IMediator mediator;

        public ProcessEngineController(IMediator mediator)
        {
            this.mediator = mediator;
        }

        /// <summary>
        /// 创建-表单类别        
        /// </summary>
        /// <param name="request">表单类别请求参数</param>
        /// <returns>受影响函数</returns>

        [HttpPost]
        public Task<ApiResult<int>> CreateFormCategory(CreateFormCategoryCommand request) {
            return mediator.Send(request);
        }

        /// <summary>
        /// 更新-表单类别
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPut]
        public   Task<ApiResult<int>> UpdateFormCategory(UpdateFormCategoryCommand request) {
            return mediator.Send(request);
        }

        /// <summary>
        /// 逻辑删除-表单类别
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPut]
        public   Task<ApiResult<int>> DelFormCategory(DelFormCategoryCommand request) {
            return mediator.Send(request);
        }


        #region 流程表单
        /// <summary>
        /// 添加流程表单接口
        /// </summary>
        /// <param name="request">表单的参数</param>
        /// <returns>响应包装类对象</returns>
        [HttpPost]
        public   Task<ApiResult<int>> CreateForm(CreateFormCommand request) {
            return mediator.Send(request);
        }

        /// <summary>
        /// 修改流程表单接口
        /// </summary>
        /// <param name="request">表单的参数</param>
        /// <returns>响应包装类对象</returns>
        [HttpPut]
        public Task<ApiResult<int>> UpdateForm(UpdateFormCommand request)
        {
            return mediator.Send(request);
        }

        /// <summary>
        /// 删除流程表单接口
        /// </summary>
        /// <param name="request">表单的参数</param>
        /// <returns>响应包装类对象</returns>
        [HttpPut]
        public  Task<ApiResult<int>> DelForm(DelFormCommand request) {

            return mediator.Send(request);
        }

        #endregion

        #region 测试全局异常过滤器
        /// <summary>
        /// 用于测试全局异常过滤器
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public string TestException() {

            var i = 0;
            var j = 1 / i;
            return "有异常";
        }

        #endregion

        #region 表单明细-字段更新

        /// <summary>
        /// 批量保存流程表单明细(自定义的流程动态字段)
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost]
        public   Task<ApiResult<int>> SaveFormField(CreateFormFieldCommand request) {
            return mediator.Send(request);
        }
        #endregion

    }
}
